<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html xmlns:th="" lang="zh-CN">
<%@include file="/WEB-INF/pages/base/include_article.jsp"%>
<body>
<div id="wrapper">
    <%@include file="/WEB-INF/pages/base/menu.jsp"%>
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h3 class="page-header">商品管理</h3>
            </div>
        </div>
        <div class="row">
            <form class="form-horizontal" data-parsley-validate>
                <div class="col-lg-12 col-md-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">商品基本信息</div>
                        <div class="panel-body">
                            <div class="row">
                                <div class="col-lg-12 col-md-12">
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品名称：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="name" class="form-control" placeholder="请输入商品名称"
                                                   required  onkeyup = "ValidateValue(this)">
                                        </div>
                                        <div class="col-lg-2 clo-md-2">
                                            <span class="help-block">*必须填写</span>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品销售价：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="salesPrice" class="form-control"
                                                   placeholder="请输入商品销售价">
                                        </div>
                                        <div class="col-lg-2 clo-md-2">
                                            <span class="help-block">*必须填写</span>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品市场价：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="marketPrice" class="form-control"
                                                   placeholder="请输入商品佣金额">
                                        </div>
                                        <div class="col-lg-2 clo-md-2">
                                            <span class="help-block">*必须填写</span>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品库存：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="stock" class="form-control"
                                                   placeholder="请输入商品库存" onkeyup="value=value.replace(/[^\d]/g,'')">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品限购数量：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="stockAlgorithm" class="form-control"
                                                   placeholder="请输入商品限购数量" onkeyup="value=value.replace(/[^\d]/g,'')">
                                        </div>
                                    </div>
                                    
                                    <div class="form-group" id="orderNumber_div" >
                                        <label class="col-lg-2 clo-md-2 control-label">商品首页推荐排列顺序<br>(数字越小越靠前)：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="orderNumber" class="form-control"
                                                   placeholder="请输入商品首页排列顺序"  onkeyup="value=value.replace(/[^\d]/g,'')">
                                        </div>
                                    </div>
                                    
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">开始时间：</label>
                                        <div class="col-lg-8">
                                            <input class="form-control" id="startTime" type="text" placeholder="开始时间">
                                        </div>
                                        <div class="col-lg-2 clo-md-2">
                                            <span class="help-block">*必须选择</span>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">结束时间：</label>
                                        <div class="col-lg-8">
                                            <input class="form-control" id="endingTime" type="text" placeholder="结束时间">
                                        </div>
                                        <div class="col-lg-2 clo-md-2">
                                            <span class="help-block">*必须选择</span>
                                        </div>
                                    </div>
                                    
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商盟惠购说订阅号文章链接：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="nuoaUrl" class="form-control"
                                                   placeholder="请输入链接地址">
                                        </div>
                                    </div>
                                    <!-- <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品评级编号：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="certificateNumber" class="form-control"
                                                   placeholder="请输入商品评级编号">
                                        </div>
                                    </div> -->
                                    <div class="form-group">
                                         <label class="col-lg-2 clo-md-2 control-label">商品规格图<br>(800 X 800)：</label>
                                         <div class="col-lg-8">
                                             <p><img id="formatImage" src="" width="50px"></p>
                                             <button class="btn btn-default" id="photoUpload_3">上传图片</button>
                                         </div>
                                     </div>
                                     <div class="form-group no-filereader-hidden">
                                        <label class="col-sm-2 control-label"></label>
                                        <div class="col-sm-10">
                                            <div class="tag-wrapper" id="attachmentTag_3"></div>
                                        </div>
                                    </div>
   
    
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">品牌名称：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="brandName" class="form-control"
                                                   placeholder="请输入品牌名称" onkeyup = "ValidateValue(this)">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">净含量：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="netVolume" class="form-control"
                                                   placeholder="请输入净含量" onkeyup = "ValidateValue(this)">
                                        </div>  
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">产地：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="placeOfOrigin" class="form-control"
                                                   placeholder="请输入产地" onkeyup = "ValidateValue(this)">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">生产日期：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="manufacturerDate" class="form-control"
                                                   placeholder="请输入生产日期">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">成分：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="storageMethod" class="form-control"
                                                   placeholder="请输入成分" onkeyup = "ValidateValue(this)">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">保质期：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="durabilityPeriod" class="form-control"
                                                   placeholder="请输入保质期">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">适用人群：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="peopleFor" class="form-control"
                                                   placeholder="请输入适用人群" onkeyup = "ValidateValue(this)">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">使用方法：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="useMethod" class="form-control"
                                                   placeholder="请输入使用方法" onkeyup = "ValidateValue(this)">
                                        </div>
                                    </div>
                                    
                                    <!--  
                                    
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品质地：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="textureName" class="form-control"
                                                   placeholder="请输入商品质地">
                                        </div>  
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">遮光指数：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="shadingIndex" class="form-control"
                                                   placeholder="请输入遮光指数">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">厚度指数：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="thicknessIndex" class="form-control"
                                                   placeholder="请输入厚度指数">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">垂坠指数：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="sagIndex" class="form-control"
                                                   placeholder="请输入垂坠指数">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">布棉工艺：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="cottonsTechnics" class="form-control"
                                                   placeholder="请输入布棉工艺">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">纱棉工艺：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="yarnTechnics" class="form-control"
                                                   placeholder="请输入纱棉工艺">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品风格：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="styleName" class="form-control"
                                                   placeholder="请输入商品风格">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">布商品重量：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="weightOfCloth" class="form-control"
                                                   placeholder="请输入布商品重量">
                                        </div>
                                    </div>
    								<div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">纱商品重量：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="weightOfYarn" class="form-control"
                                                   placeholder="请输入纱商品重量">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">洗涤方式：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="washingMethod" class="form-control"
                                                   placeholder="请输入洗涤方式">
                                        </div>
                                    </div>
                                    
                                    -->
                                      
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品供应商：</label>
                                    	<div class="col-lg-8" id="productSellerList">
                                    	</div>
                                    	<div class="col-lg-2 clo-md-2">
                                            <span class="help-block">*必须填写</span>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品销售范围：</label>
                                        <div class="col-lg-8" id="mallList">
                                        	<%-- <c:forEach var="item" items="${mallList}" varStatus="status">
						                             <input type="checkbox" name="saleArea" value="${item.mallUuid}" checked>${item.mallName}
						                    </c:forEach> --%>
                                        </div>
                                        <div class="col-lg-2 clo-md-2">
                                            <span class="help-block">*必须填写</span>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品首页展示类型：</label>
                                    	<div class="col-lg-8">
	                                        <select class="form-control" id="productType">
		                                            <option value="0">单排</option>
		                                            <option value="1">双排</option>
	                                        </select>
	                                        <input type="hidden" id="productType_hidden" >
                                    	</div>
                                    	<div class="col-lg-2 clo-md-2">
                                            <span class="help-block">*必须填写</span>
                                        </div>
                                    </div>
                                     <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品一级类别：</label>
                                    	<div class="col-lg-8" id="categoryList">
                                    	</div>
                                    	<div class="col-lg-2 clo-md-2">
                                            <span class="help-block">*必须填写</span>
                                        </div>
                                    </div>
                                    
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">积分返利比例(%)：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="backPercent" class="form-control"
                                                   placeholder="请输入积分返利比例">
                                        </div>
                                    </div>
                                    
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">首次购买给合伙人奖励比例(%)：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="partnerReward" class="form-control"
                                                   placeholder="请输入首次购买给合伙人奖励比例">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">第二次购买给合伙人奖励比例(%)：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="partnerReward2" class="form-control"
                                                   placeholder="请输入第二次购买给合伙人奖励比例">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">首次购买给店主奖励比例(%)：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="shopReward" class="form-control"
                                                   placeholder="请输入首次购买给店主奖励比例">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">第二次购买给店主奖励比例(%)：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="shopReward2" class="form-control"
                                                   placeholder="请输入第二次购买给店主奖励比例">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">首次购买给会员奖励比例(%)：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="nomalReward" class="form-control"
                                                   placeholder="请输入首次购买给会员奖励比例">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">第二次购买给会员奖励比例(二级)(%)：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="nomalReward2" class="form-control"
                                                   placeholder="请输入第二次购买给会员奖励比例">
                                        </div>
                                    </div>
                                    
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品打折满足金额(元)：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="uplevelPrice" class="form-control"
                                                   placeholder="请输入打折满足金额">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品打折折扣(%)：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="uplevelPercent" class="form-control"
                                                   placeholder="请输入打折折扣">
                                        </div>
                                    </div>
                                    
                                    <!--
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品平台佣金(%)：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="platformReward" class="form-control"
                                                   placeholder="请输入商品平台佣金">
                                        </div>
                                    </div> -->
                                    <!-- <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品回购手续(%)：</label>
                                        <div class="col-lg-8">
                                            <input type="text" id="backPercent" class="form-control"
                                                   placeholder="请输入商品回购手续比例">
                                        </div>
                                    </div> -->
                                    <!-- <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品用户佣金：</label>
                                        <div class="col-lg-8">
                                        	<p id="accountRewardList"></p>
                                        	<p onclick="addNewReward()" style="border:1px solid gray;padding-left:50px;border-radius:5px;cursor:pointer;margin:15px 5px 15px 0px;width:20%">添加</p>
                                        </div>
                                    </div> -->
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商城首页简述：</label>
                                        <div class="col-lg-8">
                                            <textarea class="form-control" rows="3" id="shortName"
                                                      placeholder="请输入商品简述" onkeyup = "ValidateValue(this)"></textarea>
                                        </div>
                                    </div>
                                    <!-- <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商城首页详述：</label>
                                        <div class="col-lg-8">
                                            <textarea class="form-control" rows="3" id="sellingPoint"
                                                      placeholder="请输入商品详述"></textarea>
                                        </div>
                                    </div> -->
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品详情页描述：</label>
                                        <div class="col-lg-8">
                                            <textarea class="form-control" rows="3" id="desc"
                                                      placeholder="请输入商品描述" onkeyup = "ValidateValue(this)"></textarea>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-2 control-label">商品备注：</label>
                                        <div class="col-lg-8">
                                            <textarea class="form-control" rows="3" id="remark"
                                                      placeholder="请输入商品备注" onkeyup = "ValidateValue(this)"></textarea>
                                        </div>
                                    </div>
                                    <hr>
                                    <div class="form-group">
                                         <label class="col-lg-2 clo-md-2 control-label">商品海报图<br>(750 X 450)：</label>
                                         <div class="col-lg-8">
                                             <p><img id="image5" src="" width="200px"></p>
                                             <button class="btn btn-default" id="photoUpload_4">上传图片</button>
                                         </div>
                                     </div>
                                    <div class="form-group">
                                        <label class="col-lg-2 clo-md-12 control-label">商品照片<br>(750 X 450)：</label>
                                        <div class="col-lg-10 col-md-12 ">
                                            <button class="btn btn-default" id="photoUpload_1">上传图片</button>
                                            <div class="clearfix"></div>
                                            <span class="help-block" style="display: inline-block;">(1~4张图片)</span>
                                            <input type="hidden" name="attachmentUuid_1"/>
                                            <input type="hidden" name="attachmentUrl_1"
                                                   value=""/>
                                        </div>
                                    </div>
                                    <div class="form-group no-filereader-hidden">
                                        <label class="col-sm-2 control-label"></label>
                                        <div class="col-sm-10">
                                            <div class="tag-wrapper" id="attachmentTag_1"></div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-1 clo-md-1 control-label">详情：</label>
                                        <div class="col-lg-8">
                                            <script id="editor" name="upfile" type="text/plain" style="width:1024px;height:500px;"/>
                                        </div>
                                        <div class="col-lg-1 clo-md-1">
                                            <span class="help-block">*必须填写</span>
                                        </div>
                                    </div>
                                    <!-- <div class="form-group">
                                        <label class="col-lg-2 clo-md-12 control-label">商品详情图<br>(800 X 800)：</label>
                                        <div class="col-lg-10 col-md-12 ">
                                            <button class="btn btn-default" id="photoUpload_2">上传图片</button>
                                            <div class="clearfix"></div>
                                            <span class="help-block" style="display: inline-block;">(1~12张图片)</span>
                                            <input type="hidden" name="attachmentUuid_2"/>
                                            <input type="hidden" name="attachmentUrl_2"
                                                   value=""/>
                                        </div>
                                    </div>
                                    <div class="form-group no-filereader-hidden">
                                        <label class="col-sm-2 control-label"></label>
                                        <div class="col-sm-10">
                                            <div class="tag-wrapper" id="attachmentTag_2"></div>
                                        </div>
                                    </div> -->
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="clearfix"></div>
                <button type="button" class="btn btn-primary" onclick="product_modify()"
                        style="margin-left:15px;margin-bottom:30px;">修改
                </button>
                <button class="btn btn-default" id="cancel" style="margin-left:15px;margin-bottom:30px;">
                    取消
                </button>
                <button class="btn btn-default" id="sadasdasd" style="margin-left:15px;margin-bottom:30px;">
                    查询
                </button>
            </form>
        </div>
    </div>
</div>
<script>
	function ValidateValue(textbox) {
		var IllegalString = "[`~!#$^&*=|{}':;',\\[\\].<>/?~！#￥……&*——|{}【】‘；：”“'。，、？]‘’";
		var textboxvalue = textbox.value;
		var index = textboxvalue.length - 1;
		var s = textbox.value.charAt(index);
		if (IllegalString.indexOf(s) >= 0) {
			s = textboxvalue.substring(0, index);
			textbox.value = s;
		}
	} 

	//实例化编辑器
	//建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
	var ue = UE.getEditor('editor');
	UE.Editor.prototype._bkGetActionUrl=UE.Editor.prototype.getActionUrl;
	UE.Editor.prototype.getActionUrl=function(action){
	    if (action == 'uploadimage' ||action== 'uploadscrawl' || action == 'uploadimage') {
	    	//return this._bkGetActionUrl.call(this, action);
	    	//return '${path}/tools/imageController/upload';
	    	return '${webPath}/file/upload';
	    }else if(action =='uploadvideo') {
	    	return '${webPath}/file/upload';
	    }else if(action == 'listimage'){
	    	return this._bkGetActionUrl.call(this, action);
	    }else{
	    	return this._bkGetActionUrl.call(this, action);
	    }
	}
	
	var images = [];
	var currentI = 0;
	UE.getEditor('editor').ready(function() { 
		
		var type = "${type}";
		if(type == "3"){
			$("#orderNumber_div").hide();
		}
		
		var productId = "${productId}";
		var baseURL = "${webPath}/product/detail";
	  	var json_package = {
	       "head": {},
	       "body": {
	       	"productId": productId
	       }
	   	}
		$.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
	      if (typeof result == 'string') result = JSON.parse(result);
	      if (result.body.result == '1') {
	          alert(result.body.description)
	      } else {
	      	var product = result.body.product;
	      	$("#name").val(product.name);
	      	$("#desc").val(product.desc);
	      	$("#shortName").val(product.shortName);
            
	      	$("#remark").val(product.remark);
	      	$("#brandName").val(product.brandName);
	      	$("#netVolume").val(product.netVolume);
	      	$("#placeOfOrigin").val(product.placeOfOrigin);
	      	$("#manufacturerDate").val(product.manufacturerDate);
	      	$("#storageMethod").val(product.storageMethod);
	      	$("#durabilityPeriod").val(product.durabilityPeriod);
	      	$("#peopleFor").val(product.peopleFor);
	      	$("#useMethod").val(product.useMethod);
	      	
	      	$("#salesPrice").val(product.salesPrice );
	      	$("#marketPrice").val(product.marketPrice );
	      	$("#stock").val(product.stock );
	      	$("#stockAlgorithm").val(product.stockAlgorithm );
	      	
	      	$("#orderNumber").val(product.orderNumber );
	      	$("#nuoaUrl").val(product.nuoaUrl );
	      	$("#formatImage").attr('src',product.formatImage); 
	      	$("#image5").attr('src',product.image5); 
	      	$("#startTime").val(product.startTime);
	      	$("#endingTime").val(product.endingTime);
	      	
	      	$("#attachmentUrl_1").val(product.imageList);
	      	$("#attachmentTag_1").val(product.imageList);

	      	UE.getEditor('editor').setContent(product.content,true);
	      	
	      	$("#productType").val(product.productType);
	      	$("#productType_hidden").val(product.productType);
	      	
	      	if(product.backPercent != undefined){
	      		$("#backPercent").val(product.backPercent);
	      	}
	      	if(product.partnerReward != undefined){
	      		$("#partnerReward").val(product.partnerReward);
	      	}
	      	if(product.partnerReward2 != undefined){
	      		$("#partnerReward2").val(product.partnerReward2);
	      	}
	      	if(product.shopReward != undefined){
	      		$("#shopReward").val(product.shopReward);
	      	}
            if(product.shopReward2 != undefined){
                $("#shopReward2").val(product.shopReward2);
            }
	      	if(product.nomalReward != undefined){
	      		$("#nomalReward").val(product.nomalReward);
	      	}
	      	if(product.nomalReward2 != undefined){
	      		$("#nomalReward2").val(product.nomalReward2);
	      	}
	      	
	      	if(product.uplevelPrice != undefined){
	      		$("#uplevelPrice").val(product.uplevelPrice);
	      	}
	      	if(product.uplevelPercent != undefined){
	      		$("#uplevelPercent").val(product.uplevelPercent);
	      	}
	      	
	      	for(var i=0;i<product.imageList.length;i++){
	      		images.push(product.imageList[i]);
	      	}
	      	$('input[name="attachmentUrl_1"]').val(images);
          	for(var i=0;i<product.imageList.length;i++){
          		$('#attachmentTag_1').append('<div class="col-lg-3 col-md-4" style="padding-left:0px;">'
          										+'<div class="tag-box attachment-tag uploadifive-queue-item">'
          											+'<span class="icon-attachment"></span>'
          											+'<span class="filename"></span>'
          											+'<span class="fileinfo"></span>'
          											+'<span type="button" aria-hidden="close" class="close">'
          												+'<span aria-hidden="true" style="color:#fff;">&times;</span>'
       												+'</span>'
       												+'<div class="tag-box-lower">'
       													+'<a href=' + product.imageList[i] + ' data-lightbox="example-set">'
           													+'<img src=' + product.imageList[i] + ' style="width:100%; height:auto;"/ alt="" />'
           												+'</a>'
       												+'</div>'
   												+'</div>'
											+'</div>');
          		
          		$('input[name="attachmentUrl_1"]').val();
          	}
          	
          	$("#mallList").empty();
          	if(product.mallList != undefined){
	      		var mallListString = '';
	      		for(var i=0;i<product.mallList.length;i++){
	      			if(product.mallList[i].hava == 1){
	      				mallListString += '<input type="checkbox" name="saleArea" value="'+product.mallList[i].mallUuid+'" checked>'+product.mallList[i].mallName+" ";
	      			}else{
	      				mallListString += '<input type="checkbox" name="saleArea" value="'+product.mallList[i].mallUuid+'">'+product.mallList[i].mallName+" ";
	      			}
	      		}
	      		$("#mallList").append(mallListString);
	      	}
          	
          	$("#productSellerList").empty();
          	if(product.productSellerList != undefined){
	      		var productSellerListString = '<select class="form-control" id="productSeller">';
	      		for(var i=0;i<product.productSellerList.length;i++){
	      			if(product.productSellerList[i].hava == 1){
	      				productSellerListString += '<option value="'+product.productSellerList[i].productSellerId+'" selected>'+product.productSellerList[i].productSellerName+"</option>";
	      			}else{
	      				productSellerListString += '<option value="'+product.productSellerList[i].productSellerId+'">'+product.productSellerList[i].productSellerName+"</option>";
	      			}
	      		}
	      		productSellerListString += '</select>';
	      		$("#productSellerList").append(productSellerListString);
	      	}
          	
          	$("#categoryList").empty();
          	if(product.categoryList != undefined){
	      		var categoryListString = '<select class="form-control" id="productCategory">';
	      		for(var i=0;i<product.categoryList.length;i++){
	      			console.log(product.categoryList[i]);
	      			if(product.categoryList[i].hava == 1){
	      				categoryListString += '<option value="'+product.categoryList[i].id+'" selected>'+product.categoryList[i].name+"</option>";
	      			}else{
	      				categoryListString += '<option value="'+product.categoryList[i].id+'">'+product.categoryList[i].name+"</option>";
	      			}
	      		}
	      		categoryListString += '</select>';
	      		$("#categoryList").append(categoryListString);
	      	}
	      }
	  	})
	});
	
	function product_modify() {
		var haveContent = UE.getEditor('editor').hasContents();
		if(haveContent){
    		var content = UE.getEditor('editor').getContent();
    		
    		var baseURL = "${webPath}/product/modify";
        	var productId = "${productId}";
            var name = $('#name').val();
            var salesPrice = $('#salesPrice').val();
            var marketPrice = $('#marketPrice').val();
            
            var stock = $('#stock').val();
            var stockAlgorithm = $('#stockAlgorithm').val();
            var desc = $('#desc').val();
            var remark = $('#remark').val();
            
            var shortName=$('#shortName').val();
            var sellingPoint="暂时屏蔽";
            
            var orderNumber = $('#orderNumber').val();
            var nuoaUrl = $('#nuoaUrl').val();
            var formatImage = $("#formatImage")[0].src;
            var image5 = $("#image5")[0].src;
            var startTime = $('#startTime').val();
            var endingTime = $('#endingTime').val();
            
            var attachmentUrl_1 = $('input[name="attachmentUrl_1"]').val();
            var productType = $("#productType").find("option:selected").val();
            
            var productType_hidden = $('#productType_hidden').val();
            var type = "${type}";
    		if(type != "1" && productType_hidden == 1){
    			alert("当前账号无权限操作套餐商品");
    			location.reload();
    			return;
    		}
            
            var productSeller = $("#productSeller").find("option:selected").val();
            var productCategory = $("#productCategory").find("option:selected").val();
            
            var brandName=$('#brandName').val();
    		var netVolume=$('#netVolume').val();
    		var placeOfOrigin=$('#placeOfOrigin').val();
    		var manufacturerDate=$('#manufacturerDate').val();
    		var storageMethod=$('#storageMethod').val();
    		var durabilityPeriod=$('#durabilityPeriod').val();
    		var peopleFor=$('#peopleFor').val();
    		var useMethod=$('#useMethod').val();
            
            var saleAreaList =[]; 
            $('input[name="saleArea"]:checked').each(function(){ 
            	saleAreaList.push($(this).val()); 
            }); 
            
            var backPercent = $('#backPercent').val();
            var partnerReward = $('#partnerReward').val();
            var partnerReward2 = $('#partnerReward2').val();
    		var shopReward = $('#shopReward').val();
    		//var shopReward2 = $('#saleReward2').val();
    		var nomalReward = $('#nomalReward').val();
    		var nomalReward2 = $('#nomalReward2').val();
    		var uplevelPrice = $('#uplevelPrice').val();
    		var uplevelPercent = $('#uplevelPercent').val();
    		
            var json_package = {
           		"head": {},
                "body": {
                	"productId": productId,
                    "name": name,
                    "salesPrice": salesPrice,
                    "marketPrice": marketPrice,
                    "stock": stock,
                    "stockAlgorithm": stockAlgorithm,
                    "productType":productType,
                    "productSeller":productSeller,
                    "productCategory":productCategory,
                    "saleAreaList": saleAreaList,
                    "desc": desc,
                    "remark": remark,
                    "imageList": attachmentUrl_1,
                    "content": content,
                    "shortName":shortName,
                    "sellingPoint":sellingPoint,
    				"orderNumber":orderNumber,
    				"nuoaUrl":nuoaUrl,
    				"formatImage":formatImage,
    				"image5":image5,
    				"startTime": startTime,
                    "endingTime": endingTime,
                    "partnerReward": partnerReward,
                    "partnerReward2": partnerReward2,
                    "shopReward": shopReward,
                    //"saleReward2": saleReward2,
                    "nomalReward": nomalReward,
                    "nomalReward2": nomalReward2,
                    "backPercent": backPercent,
                    "uplevelPrice": uplevelPrice,
                    "uplevelPercent": uplevelPercent,
                    "brandName": brandName,
                    "netVolume": netVolume,
                    "placeOfOrigin": placeOfOrigin,
                    "manufacturerDate": manufacturerDate,
                    "storageMethod": storageMethod,
                    "durabilityPeriod": durabilityPeriod,
                    "peopleFor": peopleFor,
                    "useMethod": useMethod
                }
            };
            $.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
                if (typeof result == 'string') result = JSON.parse(result);
                if (result.body.result == '0') {
                    alert('修改成功！')
                    window.location.reload(true);
                } else {
                    alert('修改失败！')
                }
            })
		}
    }

	function closeDiv(i){
		$("#rewardDiv"+i).remove();
		currentI--;
	}
	
	function addNewReward(){
		var accountRewardListString = '';
		accountRewardListString += '<div style="border:1px solid gray;padding:10px;border-radius:5px;margin-top:5px;" id="rewardDiv'+(currentI+1)+'">';
		accountRewardListString += '	<a style="float:right;text-decoration:none;cursor:default" onclick=closeDiv("'+(currentI+1)+'") >X</a>';
		accountRewardListString += '(一级(单位：%))<input type="text" name="rewardList" class="form-control" value="" placeholder="请输入商品用户一级佣金比例" >';
		accountRewardListString += '(二级(单位：%))<input type="text" name="rewardList2" class="form-control" value="" placeholder="请输入商品用户二级佣金比例" >';
		accountRewardListString += '(单位：天)<input type="text" name="rewardTime" class="form-control" value="" placeholder="请输入商品用户佣金时间" >';
		accountRewardListString += '</div>';
  		$("#accountRewardList").append(accountRewardListString);
  		currentI++;
	}
    $(function () {
        $('#cancel').click(function () {
            window.location.href = "${webPath}toProduct";
        })
        $('#sadasdasd').click(function () {
        	var imglist=$(".tag-box-lower img");//获取ID为div里面的所有img
        	for(var i=0;i<imglist.length;i++){ //循环为每个img设置
        		var formatImage = imglist[i].src;
        		//var formatImage = $("#formatImage")[0].src;
        		alert(formatImage);
        	}
            //window.location.href = "${webPath}toProduct";
        })
    });
	(function(){
        var attachementList = [],
        attachementUrl = [];
		var updateUpload = function () {
		    $('input[name="attachmentUuid_1"]').val(JSON.stringify({attachment: attachementList}));
		    $('input[name="attachmentUrl_1"]').val(attachementUrl);
		    $('input[name="attachmentUrl_1"]').val(images);
		};
		var updateImage = function () {
		    if (attachementUrl.length == 0) {
		        return
		    } else {
		        attachementUrl.forEach(function (attachment, index) {
		            $('#attachmentTag_1').append('<div class="col-lg-3 col-md-4" style="padding-left:0px;"><div class="tag-box attachment-tag uploadifive-queue-item"><span class="icon-attachment"></span><span class="filename"></span><span class="fileinfo"></span><span type="button" aria-hidden="close" class="close"><span aria-hidden="true" style="color:#fff;">&times;</span></span><div class="tag-box-lower"><a href="+attachment+" data-lightbox="example-set"><img src=' + attachment + ' style="width:100%; height:auto;"/ alt="" /></a></div></div></div>')
		        })
		    }
		    $('input[name="attachmentUrl_1"]').val(attachementUrl);
		};
		updateImage();
		var ajaxUpload = new AjaxUpload($('#photoUpload_1'), {
		    action: '${webPath}/file/uploadImage',
		    data: {
		        "json_package": JSON.stringify({
		            "head": {},
		            "body": {"file": "file"}
		        })
		    },
		    name: 'file',
		    onSubmit: function (file, ext) {
		        window.uploading = true;
		        $('#photoUpload_1').text('上传中...');
		        $('#photoUpload_1').attr('disabled', true);
		        this.disable();
		
		    },
		    onChange: function (file, extension) {
		        this.disable();
		    },
		    onComplete: function (file, response) {
		    	var data = JSON.parse(response);
		    	
		    	var result = data.body.result;
				var description = data.body.description;
				if(result == "1"){
					alert("图片太大");
					window.uploading = false;
					this.enable();
					return;
				}
				
				var fileUrl = data.body.fileUrl;
		    	
		        attachementUrl.push(fileUrl);
		        attachementList.push(fileUrl);
		        images.push(fileUrl);
		        updateUpload();
		        var fileName = file.length > 25 ? file.substring(0, 24) + "..." : file;
		        $('#attachmentTag_1').append('<div class="col-lg-3 col-md-4" style="padding-left:0px;"><div class="tag-box attachment-tag uploadifive-queue-item"><span class="icon-attachment"></span><span class="filename">' + fileName + ' </span><span class="fileinfo"></span><span type="button" aria-hidden="close" class="close"><span aria-hidden="true" style="color:#fff;">&times;</span></span><div class="tag-box-lower"><a href=' + fileUrl + ' data-lightbox="example-set"><img src=' + fileUrl + ' style="width:100%; height:auto;"/></a></div></div></div>');
		        window.uploading = false;
		        $('#photoUpload_1').text('上传图片');
		        this.enable();
		    }
		});
		//setTimeout("ajaxUpload()", 2000);
		
		$("#attachmentTag_1").on('click', ".attachment-tag .close", function (e) {
		    e.stopPropagation();
		    var targetTag = $(this).parents('.attachment-tag');
		    var order = $("#attachmentTag_1 .attachment-tag").index(targetTag);
		    if (order > -1) {
		        attachementList.splice(order, 1);
		        attachementUrl.splice(order, 1);
		        images.splice(order, 1);
		        updateUpload();
		        $(this).parents('.col-lg-3').remove();
		    }
		    return false
		});
	})();
	
	(function(){
		var ajaxUpload = new AjaxUpload($('#photoUpload_3'), {
		    action: '${webPath}/file/uploadImage',
		    data: {
		        "json_package": JSON.stringify({
		            "head": {},
		            "body": {"file": "file"}
		        })
		    },
		    name: 'file',
		    onSubmit: function (file, ext) {
		        window.uploading = true;
		        $('#photoUpload_3').text('上传中...');
		        $('#photoUpload_3').attr('disabled', true);
		        this.disable();
		
		    },
		    onChange: function (file, extension) {
		        this.disable();
		    },
		    onComplete: function (file, response) {
		    	var data = JSON.parse(response);

		    	var result = data.body.result;
				var description = data.body.description;
				if(result == "1"){
					alert("图片太大");
					window.uploading = false;
					this.enable();
					return;
				}
				
				var fileUrl = data.body.fileUrl;
		    	
		    	$("#formatImage").attr('src',fileUrl); 
		        window.uploading = false;
		        $('#photoUpload_3').text('上传图片');
		        this.enable();
		    }
		});
	})();
	(function(){
		var ajaxUpload = new AjaxUpload($('#photoUpload_4'), {
		    action: '${webPath}/file/uploadImage',
		    data: {
		        "json_package": JSON.stringify({
		            "head": {},
		            "body": {"file": "file"}
		        })
		    },
		    name: 'file',
		    onSubmit: function (file, ext) {
		        window.uploading = true;
		        $('#photoUpload_4').text('上传中...');
		        $('#photoUpload_4').attr('disabled', true);
		        this.disable();
		
		    },
		    onChange: function (file, extension) {
		        this.disable();
		    },
		    onComplete: function (file, response) {
		    	var data = JSON.parse(response);
		    	
		    	var result = data.body.result;
				var description = data.body.description;
				if(result == "1"){
					alert("图片太大");
					window.uploading = false;
					this.enable();
					return;
				}
				
				var fileUrl = data.body.fileUrl;
		    	
		    	$("#image5").attr('src',fileUrl); 
		        window.uploading = false;
		        $('#photoUpload_4').text('上传图片');
		        this.enable();
		    }
		});
	})();
	
	$(function () {
        $('#startTime').datetimepicker({
            format: 'YYYY-MM-DD HH:mm:ss'
        });
        $('#endingTime').datetimepicker({
            format: 'YYYY-MM-DD HH:mm:ss'
        });
        $('#startTime').datetimepicker();
        $('#endingTime').datetimepicker({
            useCurrent: false //Important! See issue #1075
        });
        $("#startTime").on("dp.change", function (e) {
            $('#endingTime').data("DateTimePicker").minDate(e.date);
        });
        $("#endingTime").on("dp.change", function (e) {
            $('#startTime').data("DateTimePicker").maxDate(e.date);
        });
    });
	
    $(document).ready(function (e) {
        $('#pro_info').keydown(function () {
            var len = $(this).val().length;
            if (len >= 100) {
                var num = $(this).val().substring(0, 99);
                $(this).val(num);
                alert("超过字数限制")
            }
        })
    });
    $(document).ready(function (e) {
        $('#pro_desc').keydown(function () {
            var len = $(this).val().length;
            if (len >= 140) {
                var num = $(this).val().substring(0, 139);
                $(this).val(num);
                alert("超过字数限制")
            }
        })
    });
</script>
</body>
</html>